<template>
	<view class="fui-wrap">
		<fui-sticky>
			<view style="background-color: #fff;">
				<fui-segmented-control @click="changeSegmented" :current="current" color="#000" activeColor="#0a8cdd" type="text" :values="status"></fui-segmented-control>
			</view>
		</fui-sticky>
		<fui-list>
			<block v-for="(item,index) in list" :key="index">
			<fui-list-cell arrow @click="$navigateTo('parking/merch/coupondetail?id='+item.id)">
				<view class="cell">
					<view class="item">
						<view class="line">
							<fui-text text="商户：" color="#afafaf" :size="28"></fui-text>
							<fui-text :text="item.merch.merch_name" color="#000" :size="28"></fui-text>
						</view>
						<view class="line">
							<fui-text text="发券时间：" color="#afafaf" :size="28"></fui-text>
							<fui-text :text="item.createtime" color="#000" :size="28"></fui-text>
						</view>
						<view class="line">
							<fui-text text="停车券：" color="#afafaf" :size="28"></fui-text>
							<fui-text :text="item.coupon.title" color="#000" :size="28"></fui-text>
						</view>
					</view>
					<view class="status">
						<fui-text :text="item.plate_number" color="#000" :size="28"></fui-text>
					</view>
				</view>
			</fui-list-cell>
			</block>
		</fui-list>
		<fui-empty v-if="list.length===0" :src="`${baseUrl}assets/img/miniapp/empty.png`" title="暂无数据!" :marginTop="200"></fui-empty>
		<filter :param="param" @confirm="doSubmit"></filter>
	</view>
</template>

<script>
	import {methods,baseUrl} from '@/utils/core.js';
	import {formatDuration,parseNumber} from '@/utils/util.js'
	import filter from '@/components/common/filter.vue';
	export default {
		components:{
			filter:filter
		},
		data() {
			return {
				baseUrl:baseUrl,
				status:['未使用','已使用','使用中','已过期','已作废'],
				current:0,
				list:[],
				page:1,
				endData:false,
				param:{
					merch_name:'',
					plate_number:'',
					starttime:'',
					endtime:''
				}
			}
		},
		onLoad(e) {
			this.getList();
		},
		onShow() {
			let refresh=uni.getStorageSync('refresh') || '';
			if(refresh){
				this.list=[];
				this.page=1;
				this.endData=false;
				uni.setStorageSync('refresh','');
				this.getList();
			}
		},
		onReachBottom() {
			this.getList();
		},
		onPullDownRefresh() {
			this.list=[];
			this.page=1;
			this.endData=false;
			this.getList(function(){
				uni.stopPullDownRefresh();
			});
		},
		methods: {
			...methods,
			formatDuration,
			parseNumber,
			changeSegmented:function(e){
				this.current=e.index;
				this.list=[];
				this.page=1;
				this.endData=false;
				this.getList();
			},
			doSubmit:function(param){
				this.param=param;
				this.list=[];
				this.page=1;
				this.endData=false;
				this.getList();
			},
			getList:function(callback=false){
				this.showPopup=false;
				if(this.endData){
					this.$msg('已经到底了');
					return;
				}
				this.$get('parking/merch/coupon-list',{
					...this.param,
					type:this.current,
					page:this.page
				},true).then(res=>{
					this.list=this.list.concat(res);
					this.page++;
					if(res.length<10){
						this.endData=true;
					}	
					if(callback){
						callback();
					}
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
.cell{
	width:100%;
	display: flex;
	align-items: center;
	justify-content: space-between;
}
.item{
	width: 75%;
	.line{
		display: flex;
		height: 50rpx;
		line-height: 50rpx;
	}
}
.status{
	width: 25%;
	text-align: right;
}
</style>